<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>cocos.director</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body>
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar">
  <tr valign="middle">
  <!-- Project homepage -->
      <!--<th class="navbar" 
            ><a class="navbar" target="_top" href="http://www.cocos2d.org/">cocos2d API reference</a></th>-->

  <!-- Tree link -->
      <th><a
        href="module-tree.html">Trees</a></th>

  <!-- Index link -->
      <th><a
        href="identifier-index.html">Indices</a></th>

  <!-- Breadcrumbs -->
      <th class="navbar-breadcrumbs">
        <span class="breadcrumbs">
          <a href="cocos-module.html">cocos</a>&nbsp;.&nbsp;director
        </span>
      </th>

      <th class="navbar last">
        <a href="javascript:toggleFrames()">Toggle&nbsp;frames</a>
      </th>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module cocos.director</h1>
<p>cocos.director.director is the singleton that creates and handles the main <tt class="rst-rst-rst-docutils literal rst-rst-docutils literal rst-docutils literal"><span class="pre">Window</span></tt>
and manages the logic behind the <tt class="rst-rst-rst-docutils literal rst-rst-docutils literal rst-docutils literal"><span class="pre">Scenes</span></tt>.</p>
<div class="rst-section" id="rst-initializing">
<h1 class="heading">Initializing</h1>
<p>The first thing to do, is to initialize the <tt class="rst-docutils literal"><span class="pre">director</span></tt>:</p>
<pre class="py-doctest">
<span class="py-keyword">from</span> cocos.director <span class="py-keyword">import</span> director
director.init( parameters )</pre>
<p>This will initialize the director, and will create a display area
(a 640x480 window by default).
The parameters that are supported by director.init() are the same
parameters that are supported by pyglet.window.Window(), plus a few
cocos exclusive ones. They are all named parameters (kwargs).
See <tt class="rst-docutils literal"><span class="pre">Director.init()</span></tt> for details.</p>
<p>Example:</p>
<pre class="py-doctest">
director.init( width=800, height=600, caption=<span class="py-string">&quot;Hello World&quot;</span>, fullscreen=True )</pre>
</div>
<div class="rst-section" id="rst-running-a-scene">
<h1 class="heading">Running a Scene</h1>
<p>Once you have initialized the director, you can run your first <tt class="rst-docutils literal"><span class="pre">Scene</span></tt>:</p>
<pre class="py-doctest">
director.run( Scene( MyLayer() ) )</pre>
<p>This will run a scene that has only 1 layer: <tt class="rst-docutils literal"><span class="pre">MyLayer()</span></tt>. You can run a scene
that has multiple layers. For more information about <tt class="rst-docutils literal"><span class="pre">Layers</span></tt> and <tt class="rst-docutils literal"><span class="pre">Scenes</span></tt>
refer to the <tt class="rst-docutils literal"><span class="pre">Layers</span></tt> and <tt class="rst-docutils literal"><span class="pre">Scene</span></tt> documentation.</p>
<p>Once a scene is running you can do the following actions:</p>
<blockquote>
<ul>
<li><dl class="rst-first rst-docutils">
<dt><tt class="rst-docutils literal"><span class="pre">director.replace(</span> <span class="pre">new_scene</span> <span class="pre">):</span></tt></dt>
<dd><p class="rst-first rst-last">Replaces the running scene with the new_scene
You could also use a transition. For example:
director.replace( SplitRowsTransition( new_scene, duration=2 ) )</p>
</dd>
</dl>
</li>
<li><dl class="rst-first rst-docutils">
<dt><tt class="rst-docutils literal"><span class="pre">director.push(</span> <span class="pre">new_scene</span> <span class="pre">):</span></tt></dt>
<dd><p class="rst-first rst-last">The running scene will be pushed to a queue of scenes to run,
and new_scene will be executed.</p>
</dd>
</dl>
</li>
<li><dl class="rst-first rst-docutils">
<dt><tt class="rst-docutils literal"><span class="pre">director.pop():</span></tt></dt>
<dd><p class="rst-first rst-last">Will pop out a scene from the queue, and it will replace the running scene.</p>
</dd>
</dl>
</li>
<li><dl class="rst-first rst-docutils">
<dt><tt class="rst-docutils literal"><span class="pre">director.scene.end(</span> <span class="pre">end_value</span> <span class="pre">):</span></tt></dt>
<dd><p class="rst-first rst-last">Finishes the current scene with an end value of <tt class="rst-docutils literal"><span class="pre">end_value</span></tt>. The next scene
to be run will be popped from the queue.</p>
</dd>
</dl>
</li>
</ul>
</blockquote>
<p>Other functions you can use are:</p>
<blockquote>
<ul class="rst-simple">
<li><tt class="rst-docutils literal"><span class="pre">director.get_window_size():</span></tt>
Returns an (x,y) pair with the _logical_ dimensions of the display.
The display might have been resized, but coordinates are always relative
to this size. If you need the _physical_ dimensions, check the dimensions
of <tt class="rst-docutils literal"><span class="pre">director.window</span></tt></li>
<li><tt class="rst-docutils literal"><span class="pre">get_virtual_coordinates(self,</span> <span class="pre">x,</span> <span class="pre">y):</span></tt>
Transforms coordinates that belongs the real (physical) window size, to
the coordinates that belongs to the virtual (logical) window. Returns
an x,y pair in logical coordinates.</li>
</ul>
</blockquote>
<p>The director also has some useful attributes:</p>
<blockquote>
<ul class="rst-simple">
<li><tt class="rst-docutils literal"><span class="pre">director.return_value</span></tt>: The value returned by the last scene that
called <tt class="rst-docutils literal"><span class="pre">director.scene.end</span></tt>. This is useful to use scenes somewhat like
function calls: you push a scene to call it, and check the return value
when the director returns control to you.</li>
<li><tt class="rst-docutils literal"><span class="pre">director.window</span></tt>: This is the pyglet window handled by this director,
if you happen to need low level access to it.</li>
<li><tt class="rst-docutils literal"><span class="pre">self.show_FPS</span></tt>: You can set this to a boolean value to enable, disable
the framerate indicator.</li>
<li><tt class="rst-docutils literal"><span class="pre">self.scene</span></tt>: The scene currently active</li>
</ul>
</blockquote>
</div>

<!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></a>
        <h2>Classes</h2>
<table class="summary">
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="cocos.director.DefaultHandler-class.html" class="summary-name">DefaultHandler</a>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="cocos.director.Director-class.html" class="summary-name">Director</a>
<div class="summary-description">Class that creates and handle the main Window and manages how
and when to execute the Scenes</div>
    </td>
  </tr>
</table>
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
        <h2>Variables</h2>
<table class="summary">
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="director"></a><span class="summary-name">director</span> = <code title="Director()">Director()</code>
    </td>
  </tr>
</table>
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar">
  <tr valign="middle">
  <!-- Project homepage -->
      <!--<th class="navbar" 
            ><a class="navbar" target="_top" href="http://www.cocos2d.org/">cocos2d API reference</a></th>-->

  <!-- Tree link -->
      <th><a
        href="module-tree.html">Trees</a></th>

  <!-- Index link -->
      <th><a
        href="identifier-index.html">Indices</a></th>

  <!-- Breadcrumbs -->
      <th class="navbar-breadcrumbs">
        <span class="breadcrumbs">
          <a href="cocos-module.html">cocos</a>&nbsp;.&nbsp;director
        </span>
      </th>

      <th class="navbar last">
        <a href="javascript:toggleFrames()">Toggle&nbsp;frames</a>
      </th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0beta1 on Wed Oct 26 10:00:11 2011
    </td>
    <td align="right" class="footer">
      <a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie()
  // -->
</script>
  
</body>
</html>
